<template>
  <div>
    <div class="main_mv">
      <div class="head">
        <span
          class="iconfont icon-fanhui"
          @click="$router.push('/recommend')"
        ></span>
      </div>
      <div class="box">
        <video ref="video" :src="url" controls @loadeddata="mvPlay"></video>
      </div>
      <div class="recommend_mv">
        <h3>盐选MV</h3>
        <!-- <div
          class="box"
          v-for="(item) in Mv163"
          :key="item.id"
        > -->
        <router-link
          class="box"
          v-for="item in Mv163"
          :key="item.id"
          :to="'/recommend/mv?id=' + item.id"
          tag="div"
        >
          <div class="imgs">
            <img :src="item.cover" />
          </div>
          <div class="test">
            <p>{{ item.name }}</p>
          </div>
        </router-link>
        <!-- </div> -->
      </div>
    </div>
  </div>
</template>

<script>
import { getMvId, get163Mv } from "../../api/recommend";
export default {
  data() {
    return {
      url: "",
      Mv163: [
        {
          id: "",
          cover: "",
        },
      ],
      id: null,
    };
  },
  created() {
    // console.log(this.$route.query);
    let id = this.$route.query.id;
    this.id = id;
    getMvId({ id: id }).then((item) => {
      // console.log(item);
      this.url = item.data.url;
    });
    get163Mv().then((item) => {
      console.log(item);
      this.Mv163 = item.data;
    });
  },
  methods: {
    mvPlay() {
      // console.log("加载完成");
      this.$refs.video.play();
    },
  },
  watch: {
    "$route.query"() {
      location.reload();
    },
  },
};
</script>

<style lang="less">
.main_mv {
  width: 100vw;
  height: 100%;
  position: relative;
  background-color: #f2f3f4;
  .head {
    min-height: 30px;
    background-color: #d44439;
    .icon-fanhui {
      line-height: 30px;
      color: #fff;
      font-size: 20px;
      padding-left: 10px;
    }
  }
  .box {
    width: 100%;
    video {
      width: 100%;
      height: 100%;
    }
  }
  .recommend_mv {
    h3 {
      padding: 5px 10px;
    }
    .box {
      display: flex;
      align-items: center;
      .imgs {
        width: 35%;
        border-radius: 10px;
        padding: 5px 10px;
        img {
          width: 100%;
          border-radius: 10px;
        }
      }
      .test {
        width: 65%;
        p {
          width: 90%;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
      }
    }
  }
}
</style>